import axios from "axios"
import { ElMessage } from "element-plus"

const read = axios.create({
  baseURL: "http://47.99.42.133:8000/"
})
read.interceptors.request.use((config: any) => {
  const token = localStorage.getItem("token")
  if (token && config.headers) {
    config.headers.Authorization = `Bearer ${token}`
  }
  return config
},
  (error: any) => {
    return Promise.reject(error)
  }
)
read.interceptors.response.use(
  resoinse => {
    return resoinse
  },
  error => {
    /* if(error.response?.status === 401)
    {
        ElMessage.error("登录已过期，请重新登录")
        localStorage.removeItem('token')
        location.href='/'
    }
    else
    {
        ElMessage.error(error.response?.message || '请求失败')
    } */
    return Promise.reject(error)
  }
)
export { read }